/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_UNIT_TEST_LOG_H
#define SLE_UNIT_TEST_LOG_H

#ifdef __LITEOS_M__
#include "sle_unit_test_log_lite.h"
#else
#include <stdio>

/**
 * @brief check condition and return if failed.
 * 
 * @param cond condition to check
 * @return None
 */
#define SLE_UT_CHECK_AND_RETURN(cond)                         \
    do {                                                      \
        if (!(cond)) {                                        \
            SLE_UT_LOG("%s, check failed!", #cond);    \
            return;                                           \
        }                                                     \
    } while (0)

/**
 * @brief check condition and return ret if failed.
 * 
 * @param cond condition to check
 * @param ret return value
 * @return ret
 */
#define SLE_UT_CHECK_AND_RETURN_RET(cond, ret)                                       \
    do {                                                                             \
        if (!(cond)) {                                                               \
            SLE_UT_LOG("%s, check failed! ret: %s.", #cond, #ret);  \
            return ret;                                                              \
        }                                                                            \
    } while (0)

/**
 * @brief check condition and print log if failed.
 * 
 * @param cond condition to check
 * @param fmt log format
 * @return do not return
 */
#define SLE_UT_CHECK_AND_RETURN_LOG(cond, fmt, ...)  \
    do {                                      \
        if (!(cond)) {                        \
            SLE_UT_LOG(fmt, ##__VA_ARGS__); \
            return;                           \
        }                                     \
    } while (0)

/**
 * @brief check condition and print log if failed.
 * 
 * @param cond condition to check
 * @param fmt log format
 * @return do not return
 */
#define SLE_UT_CHECK_AND_PRINT_LOG(cond, fmt, ...)  \
    do {                                      \
        if (!(cond)) {                        \
            SLE_UT_LOG(fmt, ##__VA_ARGS__); \
        }                                     \
    } while (0)

/**
 * @brief check condition and return ret with log if failed.
 * 
 * @param cond condition to check
 * @param ret return value
 * @param fmt log format
 * @return ret
 */
#define SLE_UT_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \
    do {                                              \
        if (!(cond)) {                                \
            SLE_UT_LOG(fmt, ##__VA_ARGS__);         \
            return ret;                               \
        }                                             \
    } while (0)

#endif  // __LITEOS_M__
#endif // SLE_UNIT_TEST_LOG_H